﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectEuler
{
    class Problem2
    {

        public int Solve()
        {
            var fibonacciNumbers = GenerateEvenFibonacciNumbers(4000000);

            return fibonacciNumbers.Sum();
        }

        public List<int> GenerateEvenFibonacciNumbers(int maxSize)
        {
            var numbers = new List<int>();
            var i = 2;

            while (true)
            {
                var number = FibonacciNumber(i);
                if(number >= maxSize) break;
                numbers.Add(number);
                i += 3;
            }

            return numbers;
        }

        public int FibonacciNumber(int i)
        {
            switch (i)
            {
                case 0: return 0;
                case 1: return 1;
                case 2: return 2;
                default: return FibonacciNumber(i - 1) + FibonacciNumber(i - 2);
            }          
        }
    }
}
